package yf.mall.controller.api;

import com.yf.annotation.LoginUserId;
import com.yf.response.R;
import com.yf.service.WxPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import yf.mall.common.Const;
import yf.mall.dao.PointSignDao;
import yf.mall.entity.PointSignEntity;
import yf.mall.enums.AccountTypeEnum;
import yf.mall.service.AccountService;
import yf.mall.service.PointSignService;

import java.math.BigDecimal;


@RequestMapping("/api/point")
@RestController
public class ApiPointController {

    @Autowired
    private AccountService accountService;

    @Autowired
    private PointSignService pointSignService;

    /**
     * 奖励的积分数
     */
    public static BigDecimal BASE_POINT = new BigDecimal(50);

    /**
     * 分享奖励
     *
     * @return
     */
    @RequestMapping("/share")
    public R share(@LoginUserId Long userId) {
        accountService.transfer(Const.ADMIN_ID, userId, AccountTypeEnum.POINT.getIndex(), BASE_POINT, "分享奖励!");
        return R.ok();
    }


    /**
     * 积分签到
     *
     * @param userId
     * @return
     */
    @PostMapping("/sign")
    public R sign(@LoginUserId Long userId) {
        PointSignEntity signEntity = pointSignService.sign(userId, BASE_POINT);
        return R.ok(signEntity);
    }

    /**
     * 获取签到信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/sign")
    public R signInfo(@LoginUserId Long userId) {
        PointSignEntity signEntity = pointSignDao.findByUserId(userId);
        return R.ok(signEntity);
    }

    @Autowired
    private PointSignDao pointSignDao;


}
